
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
'For the parameter-This declaration is needed, to access the ArrayList class
Imports ProfileCommon
Imports System.Collections
Imports System.Web.UI.WebControls

Partial Class GTSWeb_Reports_Report1
    Inherits System.Web.UI.Page
    Private Const PARAMETER_FIELD_REF As String = "ClientBranchID"
    Private Const PARAMETER_FIELD_FROM As String = "Ship_from"
    Private Const PARAMETER_FIELD_TO As String = "Ship_To"

    Private MyConnectionInfo As ConnectionInfo

    Private Sub ConfigureCrystalReports()
        Dim reportpath As String = Server.MapPath(".\Summary.rpt")
        'Dim MyConnectionInfo As ConnectionInfo = New ConnectionInfo()
        MyConnectionInfo = New ConnectionInfo
        MyConnectionInfo.IntegratedSecurity = True
        'myConnectionInfo.Type = ConnectionInfoType.SQL
        MyConnectionInfo.ServerName = ConfigurationManager.AppSettings("DatabaseName")
        MyConnectionInfo.DatabaseName = "GTSDB"
        'MyConnectionInfo.UserID = "Terry"
        'MyConnectionInfo.Password = "bond"


        Dim user As MembershipUser = Membership.GetUser
        Dim p As ProfileCommon = ProfileCommon.Create(user.UserName)
        Dim BranchID As Integer = p.BranchId


        'Dim myArrayList As ArrayList = New ArrayList()
        'myArrayList.Add(BranchID)
        'myArrayList.Add(Sum_From_cal.SelectedDate)
        'myArrayList.Add(Sum_To_cal.SelectedDate)
        summary_CRV.ReportSource = reportpath

        Dim myParameterFields As ParameterFields = summary_CRV.ParameterFieldInfo

        SetCurrentValuesForParameterField(myParameterFields, BranchID, PARAMETER_FIELD_REF)
        SetCurrentValuesForParameterField(myParameterFields, Sum_From_cal.SelectedDate.ToShortDateString, PARAMETER_FIELD_FROM)
        SetCurrentValuesForParameterField(myParameterFields, Sum_To_cal.SelectedDate.ToShortDateString, PARAMETER_FIELD_TO)

        SetDBLogonForReport(MyConnectionInfo)


    End Sub
    Private Sub SetDBLogonForReport(ByVal myConnectionInfo As ConnectionInfo)
        Dim myTableLogOnInfos As TableLogOnInfos = summary_CRV.LogOnInfo
        For Each myTableLogOnInfo As TableLogOnInfo In myTableLogOnInfos
            myTableLogOnInfo.ConnectionInfo = myConnectionInfo
        Next
    End Sub
    Private Sub SetCurrentValuesForParameterField(ByVal myParameterFields As ParameterFields, ByVal myValue As Object, ByVal myField As String)
        'For the parameter
        ' retrieves submitted values from an ArrayList instance and places them as current values into a ParameterField instance
        Dim currentParameterValues As ParameterValues = New ParameterValues()
        Dim myParameterDiscreteValue As ParameterDiscreteValue = New ParameterDiscreteValue()
        myParameterDiscreteValue.Value = myValue
        currentParameterValues.Add(myParameterDiscreteValue)

        Dim myParameterField As ParameterField = myParameterFields(myField)
        myParameterField.CurrentValues = currentParameterValues
    End Sub

    Protected Sub summary_CRV_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles summary_CRV.Load

    End Sub

    Protected Sub GetReport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles GetReport.Click
        ConfigureCrystalReports()
    End Sub
End Class





